{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Linear Regression GUI\n",
    "\n",
    "> Understanding ML the cool way \n",
    "\n",
    "> Divyanshu Vyas | Machine Learning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from ipywidgets import interact, interactive\n",
    "from IPython.display import clear_output, display, HTML"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "def linear(m,c):\n",
    "    \n",
    "    x = np.linspace(0,100,15)\n",
    "    \n",
    "    y = 2*x -40\n",
    "    \n",
    "    plt.style.use('default')\n",
    "    \n",
    "    plt.scatter(x,y,label='Actual Data',marker='*')\n",
    "    \n",
    "    yfit = m*x + c\n",
    "    \n",
    "    plt.plot(x,yfit,color='red',label='Linear Model',lw=3)\n",
    "    \n",
    "    plt.xlabel('X-Data')\n",
    "    plt.ylabel('Y-Data')\n",
    "    \n",
    "    \n",
    "    \n",
    "    rmse = np.round(np.sqrt(np.mean((yfit-y)**2)))\n",
    "    \n",
    "    plt.title(f'LinearModel GUI\\nRMSE : {rmse}')\n",
    "    \n",
    "    plt.grid()\n",
    "    plt.legend()\n",
    "    \n",
    "    \n",
    "    plt.xlim(0,100)\n",
    "    \n",
    "    plt.ylim(-500,500)\n",
    "    \n",
    "    return x,y\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = interactive(linear,m=(-10,10),c=(-50,100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "84b0237a9e734e0a9c6c60ec0d4391c9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=0, description='m', max=10, min=-10), IntSlider(value=25, description='c…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(w)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
